unit PythonRun;
// Interfaces to parse and execute pieces of python code

interface
uses PythonTypes;

// #define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSOLUTE_IMPORT | \
//                    CO_FUTURE_WITH_STATEMENT)
// #define PyCF_MASK_OBSOLETE (CO_NESTED)

const
  PyCF_SOURCE_IS_UTF8 = $0100;
  PyCF_DONT_IMPLY_DEDENT = $0200;
  PyCF_ONLY_AST = $0400;

type
	PyCompilerFlags = record
		cf_flags: Integer;
	end;
	PyCompilerFlagsPtr = ^PyCompilerFlags;

procedure Py_SetProgramName(name: PChar); cdecl; external;
function Py_GetProgramName(): PChar; cdecl; external;

procedure Py_SetPythonHome(home: PChar); cdecl; external;
function Py_GetPythonHome(): PChar; cdecl; external;

procedure Py_Initialize(); cdecl; external;
procedure Py_InitializeEx(ex: Integer); cdecl; external;
procedure Py_Finalize(); cdecl; external;
function Py_IsInitialized(): Integer; cdecl; external;
// function Py_NewInterpreter(): PyThreadStatePtr; cdecl; external;
// procedure Py_EndInterpreter(ts: PyThreadStatePtr); cdecl; external;

function PyRun_AnyFileFlags(var f: FILE; name: PChar; flags: PyCompilerFlagsPtr): Integer; cdecl; external;
function PyRun_AnyFileExFlags(var f: FILE; name: PChar; i: Integer; flags: PyCompilerFlagsPtr): Integer; cdecl; external;
function PyRun_SimpleStringFlags(code: PChar; flags: PyCompilerFlagsPtr): Integer; cdecl; external;
function PyRun_SimpleFileExFlags(var f: FILE; name: PChar; i: Integer; flags: PyCompilerFlagsPtr): Integer; cdecl; external;
function PyRun_InteractiveOneFlags(var f: FILE; name: PChar; flags: PyCompilerFlagsPtr): Integer; cdecl; external;
function PyRun_InteractiveLoopFlags(var f: FILE; name: PChar; flags: PyCompilerFlagsPtr): Integer; cdecl; external;

// function struct _mod *) PyParser_ASTFromString(PChar , PChar , 
//             int, PyCompilerFlags *flags,
//                                                  PyArena *);
// function struct _mod *) PyParser_ASTFromFile(FILE *, PChar , int, 
//                 PChar , PChar ,
//                                                PyCompilerFlags *, int *,
//                                                PyArena *);
// #define PyParser_SimpleParseString(S, B) \
//         PyParser_SimpleParseStringFlags(S, B, 0)
// #define PyParser_SimpleParseFile(FP, S, B) \
//         PyParser_SimpleParseFileFlags(FP, S, B, 0)
// function struct _node *) PyParser_SimpleParseStringFlags(PChar , int, int);
// function struct _node *) PyParser_SimpleParseFileFlags(FILE *, PChar , int, int);

function  PyRun_StringFlags(code: PChar; i: Integer; o1, o2: PyObjectPtr; flags: PyCompilerFlagsPtr): PyObjectPtr; cdecl; external;

function  PyRun_FileExFlags(var f: FILE; name: PChar; i: Integer; o1, o2: PyObjectPtr; i2: Integer; flags: PyCompilerFlagsPtr): PyObjectPtr; cdecl; external;

// #define Py_CompileString(str, p, s) Py_CompileStringFlags(str, p, s, NULL)
// function PyObjectPtr ) Py_CompileStringFlags(PChar , PChar , int, PyCompilerFlags *);
// function struct symtable *) Py_SymtableString(PChar , PChar , int);

procedure PyErr_Print(); cdecl; external;
procedure PyErr_PrintEx(i: Integer); cdecl; external;
procedure PyErr_Display(o1, o2, o3: PyObjectPtr ); cdecl; external;

type func = procedure(); cdecl;

function Py_AtExit(f: func): Integer; cdecl; external;
procedure Py_Exit(i: Integer); cdecl; external;
function Py_FdIsInteractive(var f: FILE; name: PChar): Integer; cdecl; external;

// Bootstrap
function Py_Main(argc: Integer; argv: Array of PChar): Integer; cdecl; external;

// Use macros for a bunch of old variants
// #define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
// #define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
// #define PyRun_AnyFileEx(fp, name, closeit) \
//  PyRun_AnyFileExFlags(fp, name, closeit, NULL)
// #define PyRun_AnyFileFlags(fp, name, flags) \
//  PyRun_AnyFileExFlags(fp, name, 0, flags)
// #define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
// #define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
// #define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
// #define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
// #define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
// #define PyRun_File(fp, p, s, g, l) \
//         PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
// #define PyRun_FileEx(fp, p, s, g, l, c) \
//         PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
// #define PyRun_FileFlags(fp, p, s, g, l, flags) \
//         PyRun_FileExFlags(fp, p, s, g, l, 0, flags)

// In getpath.c
function Py_GetProgramFullPath(): PChar; cdecl; external;
function Py_GetPrefix(): PChar; cdecl; external;
function Py_GetExecPrefix(): PChar; cdecl; external;
function Py_GetPath(): PChar; cdecl; external;

// In their own files
function Py_GetVersion(): PChar; cdecl; external;
function Py_GetPlatform(): PChar; cdecl; external;
function Py_GetCopyright(): PChar; cdecl; external;
function Py_GetCompiler(): PChar; cdecl; external;
function Py_GetBuildInfo(): PChar; cdecl; external;
function _Py_svnversion(): PChar; cdecl; external;
function Py_SubversionRevision(): PChar; cdecl; external;
function Py_SubversionShortBranch(): PChar; cdecl; external;

// Internal -- various one-time initializations
function  _PyBuiltin_Init(): PyObjectPtr; cdecl; external;
function  _PySys_Init(): PyObjectPtr; cdecl; external;
procedure _PyImport_Init(); cdecl; external;
procedure _PyExc_Init(); cdecl; external;
procedure _PyImportHooks_Init(); cdecl; external;
function  _PyFrame_Init(): Integer; cdecl; external;
function  _PyInt_Init(): Integer; cdecl; external;
procedure _PyFloat_Init(); cdecl; external;

// Various internal finalizers
procedure _PyExc_Fini(); cdecl; external;
procedure _PyImport_Fini(); cdecl; external;
procedure PyMethod_Fini(); cdecl; external;
procedure PyFrame_Fini(); cdecl; external;
procedure PyCFunction_Fini(); cdecl; external;
procedure PyTuple_Fini(); cdecl; external;
procedure PyList_Fini(); cdecl; external;
procedure PySet_Fini(); cdecl; external;
procedure PyString_Fini(); cdecl; external;
procedure PyInt_Fini(); cdecl; external;
procedure PyFloat_Fini(); cdecl; external;
procedure PyOS_FiniInterrupts(); cdecl; external;

// Stuff with no proper home (yet)
function PyOS_Readline(var f, f1: FILE; s: PChar):  PChar; cdecl; external;

// var
// PyAPI_DATA(int) (*PyOS_InputHook)();
// PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, PChar );
// PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;

// Stack size, in "pointers" (so we get extra safety margins
//   on 64-bit platforms).  On a 32-bit platform, this translates
//   to a 8k margin.
const PYOS_STACK_MARGIN = 2048;

// #if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER)
// // Enable stack checking under Microsoft C */
// #define USE_STACKCHECK
// #endif
// 
// #ifdef USE_STACKCHECK
// // Check that we aren't overflowing our stack
// function int) PyOS_CheckStack();
// #endif

// Signals
// typedef  (*PyOS_sighandler_t)(int);
// function PyOS_sighandler_t) PyOS_getsig(int);
// function PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);

implementation

end.